//============================================================================================
/**
 *	@file	btwr_score.c
 *	@brief	バトルタワー成績モニタ
 *
 *	@author	??? ( D/P/PL )
 *	@date	???
 *
 *	@author	Hiroyuki Nakamura ( HG/SS )
 *	@date	08.12.22
 */
//============================================================================================

#include "common.h"
#include "gflib/touchpanel.h"
#include "system/procsys.h"
#include "system/arc_util.h"
#include "system/arc_tool.h"
#include "system/brightness.h"
#include "system/bmp_list.h"
#include "system/bmp_menu.h"
#include "system/window.h"
#include "system/pm_str.h"
#include "system/msgdata.h"
#include "system/fontproc.h"
#include "system/snd_tool.h"
#include "system/clact_util.h"
#include "system/clact_tool.h"
#include "system/render_oam.h"
#include "system/wipe.h"
#include "system/wordset.h"
#include "system/buflen.h"
#include "system/cursor_move.h"
#include "gflib/msg_print.h"
#include "gflib/strbuf_family.h"
#include "application/app_tool.h"
#include "application/pms_input.h"
#include "msgdata/msg.naix"
#include "msgdata/msg_btower_app.h"
#include "data/clact_util/clact_header.naix"

#include "application/pms_input.h"
#include "application/btwr_app.h"
//#include "savedata/savedata_def.h"
#include "savedata/config.h"
#include "savedata/b_tower.h"
#include "savedata/record.h"
#include "savedata/frontier_savedata.h"

#include "system/gamedata.h"
#include "battle/battle_common.h"
#include "battle/b_tower_data.h"

#include "btower.naix"

#include "../../frontier/graphic/frontier_obj_def.h"
#include "../../frontier/graphic/frontier_bg_def.h"


// プレイヤーリスト表示数
#define	PLAYER_PUT_H_MAX		( 3 )
#define	PLAYER_PUT_V_MAX		( 4 )
#define	PLAYER_PUT_MAX			( PLAYER_PUT_H_MAX * PLAYER_PUT_V_MAX )
#define	PLAYER_LIST_PAGE_MAX	( BTOWER_STOCK_WIFI_LEADER_MAX / PLAYER_PUT_MAX )

#define BTOWER_APP_ACTRES_MAX	(1)
#define ACT_CUR_PALT		(0)
#define ACT_CUR_PALF		(1)

enum{
	ACT_CURSOR = 0,
	ACT_RET,
	ACT_L_ARROW,
	ACT_R_ARROW,
	ACT_MAX,
};

#define	BTS_SUB_ACTOR_DISTANCE	( 512*FX32_ONE )	// サブ画面のOBJ表示Y座標オフセット

#define	CLA_H_NONE	( CLACT_U_HEADER_DATA_NONE )	// セルアクターヘッダーデータなし

#define	CLACT_ID_COMMON		( 53592 )	// この画面で使用するセルアクターのID

// キャラリソースID
enum {
	CHR_ID_OBJ = CLACT_ID_COMMON,
	CHR_ID_MAX = CHR_ID_OBJ - CLACT_ID_COMMON + 1
};
// パレットリソースID
enum {
	PAL_ID_OBJ = CLACT_ID_COMMON,
	PAL_ID_MAX = PAL_ID_OBJ - CLACT_ID_COMMON + 1
};
// セルリソースID
enum {
	CEL_ID_OBJ = CLACT_ID_COMMON,
	CEL_ID_MAX = CEL_ID_OBJ - CLACT_ID_COMMON + 1
};
// アニメリソースID
enum {
	ANM_ID_OBJ = CLACT_ID_COMMON,
	ANM_ID_MAX = ANM_ID_OBJ - CLACT_ID_COMMON + 1
};

// OBJアニメ
enum {
	OBJANM_RET_BUTTON = 0,
	OBJANM_RET_BUTTON_ANM,
	OBJANM_RET_CURSOR,
	OBJANM_L_ARROW,
	OBJANM_L_ARROW_ANM,
	OBJANM_R_ARROW,
	OBJANM_R_ARROW_ANM,
	OBJANM_NAME_CURSOR,
};

#define	PALSIZ_OBJ		( 2 )		// パレット数：通常ＯＢＪ

// ボタンＯＢＪ表示座標
#define	OBJ_RET_BUTTON_PX	( 224 )
#define	OBJ_RET_BUTTON_PY	( 176 )
// 矢印ＯＢＪ表示座標
#define	OBJ_L_ARROW_PX	( 40 )
#define	OBJ_R_ARROW_PX	( 72 )
#define	OBJ_ARROW_PY	( 176 )



#define ACT_CUR_PX	(54)
#define ACT_CUR_PY	(68)
#define ACT_RET_PX	(204)
#define ACT_RET_PY	(114)
#define ACT_RET_SX	(40)
#define ACT_RET_HSX	(20)
#define ACT_UP_PX	(128)
#define ACT_UP_PY	(52)
#define ACT_DOWN_PX	(128)
#define ACT_DOWN_PY	(132)

#define LIST_SIDE_WIDTH	(72)
#define LINE_RET		(10)
#define LINE_SCR_MAX	(LINE_RET-2)

#define FCOLS_BLACK	(GF_PRINTCOLOR_MAKE(FBMP_COL_BLACK,FBMP_COL_BLK_SDW,FBMP_COL_NULL))
#define FCOLS_WHITE	(GF_PRINTCOLOR_MAKE(FBMP_COL_WHITE,FBMP_COL_BLK_SDW,FBMP_COL_NULL))
#define FCOL_BLUE	(GF_PRINTCOLOR_MAKE(FBMP_COL_WHITE,FBMP_COL_BLK_SDW,FBMP_COL_NULL))
#define FCOL_RED	(GF_PRINTCOLOR_MAKE(FBMP_COL_WHITE,FBMP_COL_BLK_SDW,FBMP_COL_NULL))
#define FCOLA_BLACK	(GF_PRINTCOLOR_MAKE(1,2,FBMP_COL_NULL))
#define FCOLA_WHITE	(GF_PRINTCOLOR_MAKE(3,4,FBMP_COL_NULL))
#define FCOLA_ORANGE (GF_PRINTCOLOR_MAKE(5,6,FBMP_COL_NULL))
#define FCOLA_GRAY (GF_PRINTCOLOR_MAKE(7,8,FBMP_COL_NULL))
#define FCOLA_BLUE	(GF_PRINTCOLOR_MAKE(9,10,FBMP_COL_NULL))
#define FCOLA_RED	(GF_PRINTCOLOR_MAKE(11,12,FBMP_COL_NULL))

#define FONT_APP_PAL	(1)
#define FONT_SYS_PAL	(15)

#define BMPCHAR_BASE01	(192)
#define BMPCHAR_BASE02	(1)

#define WORDSET_BTOWER_APP_BUFLEN	( 512 )
//#define WORDSET_BTOWER_APP_BUFLEN	((18+1)*4)

#define	FCOL_WHITE	( 15 )		// 文字色・白

// 文字カラー
#define	FCOL_N_WHITE	( GF_PRINTCOLOR_MAKE(FCOL_WHITE,FBMP_COL_BLK_SDW,FBMP_COL_NULL) )
#define	FCOL_N_BLACK	( GF_PRINTCOLOR_MAKE(FBMP_COL_BLACK,FBMP_COL_BLK_SDW,FBMP_COL_NULL) )
#define FCOL_N_BLUE		( GF_PRINTCOLOR_MAKE(FBMP_COL_BLUE,FBMP_COL_BLU_SDW,FBMP_COL_NULL) )
#define FCOL_N_RED		( GF_PRINTCOLOR_MAKE(FBMP_COL_RED,FBMP_COL_RED_SDW,FBMP_COL_NULL) )
#define	FCOL_W_BLACK	( GF_PRINTCOLOR_MAKE(FBMP_COL_BLACK,FBMP_COL_BLK_SDW,FCOL_WHITE) )
#define	FCOL_TOUCH		( GF_PRINTCOLOR_MAKE(FCOL_WHITE,FBMP_COL_BLACK,FBMP_COL_NULL) )

// ＢＭＰＷＩＮ定義
//「もどる」
#define BMP_RET_FRM			( GF_BGL_FRAME0_M )
#define BMP_RET_PX			( 25 )
#define BMP_RET_PY			( 21 )
#define BMP_RET_SX			( 6 )
#define BMP_RET_SY			( 2 )
#define BMP_RET_PAL			( FONT_SYS_PAL )
#define BMP_RET_CGX			( 1 )
// 成績タイトル
#define BMPS_TITLE_FRM		( GF_BGL_FRAME0_M )
#define BMPS_TITLE_PX		( 5 )
#define BMPS_TITLE_PY		( 1 )
#define BMPS_TITLE_SX		( 22 )
#define BMPS_TITLE_SY		( 2 )
#define BMPS_TITLE_PAL		( FONT_SYS_PAL )
#define BMPS_TITLE_CGX		( BMP_RET_CGX + BMP_RET_SX * BMP_RET_SY )
//「げんざいのきろく」
#define BMPS_ST01_FRM		( GF_BGL_FRAME0_M )
#define BMPS_ST01_PX		( 1 )
#define BMPS_ST01_PY		( 6 )
#define BMPS_ST01_SX		( 9 )
#define BMPS_ST01_SY		( 4 )
#define BMPS_ST01_PAL		( FONT_SYS_PAL )
#define BMPS_ST01_CGX		( BMPS_TITLE_CGX + BMPS_TITLE_SX * BMPS_TITLE_SY )
//「Wi-Fiのきろく」
#define BMPS_ST02_FRM		( GF_BGL_FRAME0_M )
#define BMPS_ST02_PX		( 1 )
#define BMPS_ST02_PY		( 13 )
#define BMPS_ST02_SX		( 9 )
#define BMPS_ST02_SY		( 4 )
#define BMPS_ST02_PAL		( FONT_SYS_PAL )
#define BMPS_ST02_CGX		( BMPS_ST01_CGX + BMPS_ST01_SX * BMPS_ST01_SY )
//「ランク」
#define BMPS_RANK_FRM		( GF_BGL_FRAME0_M )
#define BMPS_RANK_PX		( 11 )
#define BMPS_RANK_PY		( 7 )
#define BMPS_RANK_SX		( 6 )
#define BMPS_RANK_SY		( 2 )
#define BMPS_RANK_PAL		( FONT_SYS_PAL )
#define BMPS_RANK_CGX		( BMPS_ST02_CGX + BMPS_ST02_SX * BMPS_ST02_SY )
// ランク
#define BMPS_RANK_NUM_FRM	( GF_BGL_FRAME0_M )
#define BMPS_RANK_NUM_PX	( 20 )
#define BMPS_RANK_NUM_PY	( 7 )
#define BMPS_RANK_NUM_SX	( 2 )
#define BMPS_RANK_NUM_SY	( 2 )
#define BMPS_RANK_NUM_PAL	( FONT_SYS_PAL )
#define BMPS_RANK_NUM_CGX	( BMPS_RANK_CGX + BMPS_RANK_SX * BMPS_RANK_SY )
//「ぜんかい」
#define BMPS_OLD_FRM		( GF_BGL_FRAME0_M )
#define BMPS_OLD_PX			( 11 )
#define BMPS_OLD_PY			( 13 )
#define BMPS_OLD_SX			( 6 )
#define BMPS_OLD_SY			( 2 )
#define BMPS_OLD_PAL		( FONT_SYS_PAL )
#define BMPS_OLD_CGX		( BMPS_RANK_NUM_CGX + BMPS_RANK_NUM_SX * BMPS_RANK_NUM_SY )
// 前回の連勝数
#define BMPS_OLD_WIN_FRM	( GF_BGL_FRAME0_M )
#define BMPS_OLD_WIN_PX		( 18 )
#define BMPS_OLD_WIN_PY		( 13 )
#define BMPS_OLD_WIN_SX		( 4 )
#define BMPS_OLD_WIN_SY		( 2 )
#define BMPS_OLD_WIN_PAL	( FONT_SYS_PAL )
#define BMPS_OLD_WIN_CGX	( BMPS_OLD_CGX + BMPS_OLD_SX * BMPS_OLD_SY )
//「れんしょう」（前回）
#define BMPS_OLD_STR_FRM	( GF_BGL_FRAME0_M )
#define BMPS_OLD_STR_PX		( 22 )
#define BMPS_OLD_STR_PY		( 13 )
#define BMPS_OLD_STR_SX		( 8 )
#define BMPS_OLD_STR_SY		( 2 )
#define BMPS_OLD_STR_PAL	( FONT_SYS_PAL )
#define BMPS_OLD_STR_CGX	( BMPS_OLD_WIN_CGX + BMPS_OLD_WIN_SX * BMPS_OLD_WIN_SY )
//「さいこう」
#define BMPS_BST_FRM		( GF_BGL_FRAME0_M )
#define BMPS_BST_PX			( 11 )
#define BMPS_BST_PY			( 16 )
#define BMPS_BST_SX			( 6 )
#define BMPS_BST_SY			( 2 )
#define BMPS_BST_PAL		( FONT_SYS_PAL )
#define BMPS_BST_CGX		( BMPS_OLD_STR_CGX + BMPS_OLD_STR_SX * BMPS_OLD_STR_SY )
// 最高連勝数
#define BMPS_BST_WIN_FRM	( GF_BGL_FRAME0_M )
#define BMPS_BST_WIN_PX		( 18 )
#define BMPS_BST_WIN_PY		( 16 )
#define BMPS_BST_WIN_SX		( 4 )
#define BMPS_BST_WIN_SY		( 2 )
#define BMPS_BST_WIN_PAL	( FONT_SYS_PAL )
#define BMPS_BST_WIN_CGX	( BMPS_BST_CGX + BMPS_BST_SX * BMPS_BST_SY )
//「れんしょう」（最高）
#define BMPS_BST_STR_FRM	( GF_BGL_FRAME0_M )
#define BMPS_BST_STR_PX		( 22 )
#define BMPS_BST_STR_PY		( 16 )
#define BMPS_BST_STR_SX		( 8 )
#define BMPS_BST_STR_SY		( 2 )
#define BMPS_BST_STR_PAL	( FONT_SYS_PAL )
#define BMPS_BST_STR_CGX	( BMPS_BST_WIN_CGX + BMPS_BST_WIN_SX * BMPS_BST_WIN_SY )

// リーダー情報
#define BMPL_INFO_FRM		( GF_BGL_FRAME0_S )
#define BMPL_INFO_PX		( 2 )
#define BMPL_INFO_PY		( 7 )
#define BMPL_INFO_SX		( 28 )
#define BMPL_INFO_SY		( 2 )
#define BMPL_INFO_PAL		( FONT_SYS_PAL )
#define BMPL_INFO_CGX		( 1 )
#define BMPL_INFO_S_CGX		( BMPL_INFO_CGX + BMPL_INFO_SX * BMPL_INFO_SY )
// 住所
#define BMPL_ADRS_FRM		( GF_BGL_FRAME0_S )
#define BMPL_ADRS_PX		( 2 )
#define BMPL_ADRS_PY		( 10 )
#define BMPL_ADRS_SX		( 28 )
#define BMPL_ADRS_SY		( 6 )
#define BMPL_ADRS_PAL		( FONT_SYS_PAL )
#define BMPL_ADRS_CGX		( BMPL_INFO_S_CGX + BMPL_INFO_SX * BMPL_INFO_SY )
#define BMPL_ADRS_S_CGX		( BMPL_ADRS_CGX + BMPL_ADRS_SX * BMPL_ADRS_SY )
// 挨拶
#define BMPL_COMM_FRM		( GF_BGL_FRAME0_S )
#define BMPL_COMM_PX		( 2 )
#define BMPL_COMM_PY		( 17 )
#define BMPL_COMM_SX		( 28 )
#define BMPL_COMM_SY		( 6 )
#define BMPL_COMM_PAL		( FONT_SYS_PAL )
#define BMPL_COMM_CGX		( BMPL_ADRS_S_CGX + BMPL_ADRS_SX * BMPL_ADRS_SY )
#define BMPL_COMM_S_CGX		( BMPL_COMM_CGX + BMPL_COMM_SX * BMPL_COMM_SY )
//「ランク」
#define BMPL_RANK_FRM		( GF_BGL_FRAME0_M )
#define BMPL_RANK_PX		( 5 )
#define BMPL_RANK_PY		( 1 )
#define BMPL_RANK_SX		( 8 )
#define BMPL_RANK_SY		( 2 )
#define BMPL_RANK_PAL		( FONT_SYS_PAL )
#define BMPL_RANK_CGX		( BMP_RET_CGX + BMP_RET_SX * BMP_RET_SY )
//「バトルルーム」
#define BMPL_ROOM_FRM		( GF_BGL_FRAME0_M )
#define BMPL_ROOM_PX		( 15 )
#define BMPL_ROOM_PY		( 1 )
#define BMPL_ROOM_SX		( 12 )
#define BMPL_ROOM_SY		( 2 )
#define BMPL_ROOM_PAL		( FONT_SYS_PAL )
#define BMPL_ROOM_CGX		( BMPL_RANK_CGX + BMPL_RANK_SX * BMPL_RANK_SY )
// タイトル
#define BMPL_TITLE_FRM		( GF_BGL_FRAME0_M )
#define BMPL_TITLE_PX		( 5 )
#define BMPL_TITLE_PY		( 3 )
#define BMPL_TITLE_SX		( 22 )
#define BMPL_TITLE_SY		( 2 )
#define BMPL_TITLE_PAL		( FONT_SYS_PAL )
#define BMPL_TITLE_CGX		( BMPL_ROOM_CGX + BMPL_ROOM_SX * BMPL_ROOM_SY )
// ページ
#define BMPL_PAGE_FRM		( GF_BGL_FRAME0_M )
#define BMPL_PAGE_PX		( 15 )
#define BMPL_PAGE_PY		( 21 )
#define BMPL_PAGE_SX		( 4 )
#define BMPL_PAGE_SY		( 2 )
#define BMPL_PAGE_PAL		( FONT_SYS_PAL )
#define BMPL_PAGE_CGX		( BMPL_TITLE_CGX + BMPL_TITLE_SX * BMPL_TITLE_SY )
// 名前
#define BMPL_NAME_FRM		( GF_BGL_FRAME0_M )
#define BMPL_NAME_SX		( 8 )
#define BMPL_NAME_SY		( 2 )
#define BMPL_NAME_PAL		( FONT_SYS_PAL )
#define BMPL_NAME01_PX		( 3 )
#define BMPL_NAME01_PY		( 7 )
#define BMPL_NAME01_CGX		( BMPL_PAGE_CGX + BMPL_PAGE_SX * BMPL_PAGE_SY )
#define BMPL_NAME02_PX		( 12 )
#define BMPL_NAME02_PY		( 7 )
#define BMPL_NAME02_CGX		( BMPL_NAME01_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME03_PX		( 21 )
#define BMPL_NAME03_PY		( 7 )
#define BMPL_NAME03_CGX		( BMPL_NAME02_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME04_PX		( 3 )
#define BMPL_NAME04_PY		( 10 )
#define BMPL_NAME04_CGX		( BMPL_NAME03_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME05_PX		( 12 )
#define BMPL_NAME05_PY		( 10 )
#define BMPL_NAME05_CGX		( BMPL_NAME04_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME06_PX		( 21 )
#define BMPL_NAME06_PY		( 10 )
#define BMPL_NAME06_CGX		( BMPL_NAME05_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME07_PX		( 3 )
#define BMPL_NAME07_PY		( 13 )
#define BMPL_NAME07_CGX		( BMPL_NAME06_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME08_PX		( 12 )
#define BMPL_NAME08_PY		( 13 )
#define BMPL_NAME08_CGX		( BMPL_NAME07_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME09_PX		( 21 )
#define BMPL_NAME09_PY		( 13 )
#define BMPL_NAME09_CGX		( BMPL_NAME08_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME0A_PX		( 3 )
#define BMPL_NAME0A_PY		( 16 )
#define BMPL_NAME0A_CGX		( BMPL_NAME09_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME0B_PX		( 12 )
#define BMPL_NAME0B_PY		( 16 )
#define BMPL_NAME0B_CGX		( BMPL_NAME0A_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME0C_PX		( 21 )
#define BMPL_NAME0C_PY		( 16 )
#define BMPL_NAME0C_CGX		( BMPL_NAME0B_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME11_CGX		( BMPL_NAME0C_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME12_CGX		( BMPL_NAME11_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME13_CGX		( BMPL_NAME12_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME14_CGX		( BMPL_NAME13_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME15_CGX		( BMPL_NAME14_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME16_CGX		( BMPL_NAME15_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME17_CGX		( BMPL_NAME16_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME18_CGX		( BMPL_NAME17_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME19_CGX		( BMPL_NAME18_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME1A_CGX		( BMPL_NAME19_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME1B_CGX		( BMPL_NAME1A_CGX + BMPL_NAME_SX * BMPL_NAME_SY )
#define BMPL_NAME1C_CGX		( BMPL_NAME1B_CGX + BMPL_NAME_SX * BMPL_NAME_SY )


// 成績画面BMPWIN ID
enum{
	WINS_RET = 0,	//「もどる」
	WINS_TITLE,		// 成績タイトル
	WINS_ST01,		//「げんざいのきろく」
	WINS_ST02,		//「Wi-Fiのきろく」
	WINS_RANK,		//「ランク」
	WINS_RANK_NUM,	// ランク
	WINS_OLD,		//「ぜんかい」
	WINS_OLD_WIN,	// 前回の連勝数
	WINS_OLD_STR,	//「れんしょう」（前回）
	WINS_BST,		//「さいこう」
	WINS_BST_WIN,	// 最高連勝数
	WINS_BST_STR,	//「れんしょう」（最高）
	WINS_MAX
};

// リーダー一覧BMPWIN ID
enum{
	WINL_RET = 0,	//「もどる」
	WINL_RANK,		//「ランク」
	WINL_ROOM,		//「バトルルーム」
	WINL_TITLE,		// タイトル
	WINL_PAGE,		// ページ
	WINL_INFO,		// リーダー情報
	WINL_ADRS,		// 住所
	WINL_COMM,		// 挨拶
	WINL_INFO_S,	// リーダー情報（スワップ）
	WINL_ADRS_S,	// 住所（スワップ）
	WINL_COMM_S,	// 挨拶（スワップ）
	WINL_NAME01,	// 名前
	WINL_NAME02,
	WINL_NAME03,
	WINL_NAME04,
	WINL_NAME05,
	WINL_NAME06,
	WINL_NAME07,
	WINL_NAME08,
	WINL_NAME09,
	WINL_NAME0A,
	WINL_NAME0B,
	WINL_NAME0C,
	WINL_NAME11,	// 名前（スワップ）
	WINL_NAME12,
	WINL_NAME13,
	WINL_NAME14,
	WINL_NAME15,
	WINL_NAME16,
	WINL_NAME17,
	WINL_NAME18,
	WINL_NAME19,
	WINL_NAME1A,
	WINL_NAME1B,
	WINL_NAME1C,
	WINL_MAX,
};

// 文字列表示定義
enum {
	STRPRINT_MODE_LEFT = 0,	// 左詰
	STRPRINT_MODE_RIGHT,	// 右詰
	STRPRINT_MODE_CENTER,	// 中央
};

// ボタンアニメモード
enum {
	BTN_ANM_MODE_OBJ = 0,
	BTN_ANM_MODE_BG,
};

typedef struct _APP_MSG{
	MSGDATA_MANAGER*	pMan;

	WORDSET* wset;	//ワーク
	STRBUF*	tmp;	//汎用
	STRBUF* ebuf;	//もどる
	STRBUF* tbuf;	//タイトル
	STRBUF*	nbuf;	//名前
	STRBUF*	a1buf;	//地域(国名と地域名)
	STRBUF*	a2buf;	//地域(国名のみ)
	STRBUF*	cbuf;	//地域NGコード
	STRBUF*	rbuf[6];
	STRBUF*	def_name[2];	///<デフォルトネーム展開
}APP_MSG;

//リーダーデータ
typedef struct _LEADER_DATA{
	STRBUF*	name;	//名前
	u8		sex;	//性別
	u8		country;	//国コード
	u8		area;		//地域コード
	u8		ngname_f;	//NGネームフラグ
	PMS_DATA	msg;		//簡易会話メッセージ
}LEADER_DATA;

typedef struct _BTOWER_APP_WORK{
	int	heapID;
	int	seq;
	u16	mainMode;
	u8	subMode;

	u8	line;
	u8	side;
	u8	state;
	u8	upLine;
	u8	viewLine;

	GF_BGL_INI			*bgl;
	BTOWER_APP_PARAM	*param;
	CONFIG				*configSave;
	FRONTIER_SAVEWORK	*frontierSave;
	BTLTOWER_SCOREWORK	*scoreSave;
	BTLTOWER_WIFI_DATA	*wifiSave;

	///メッセージリソース
	APP_MSG			msgDat;
	GF_BGL_BMPWIN	win[WINL_MAX];	///<BMPウィンドウデータ

	//リーダーデータ
	LEADER_DATA		leader[BTOWER_STOCK_WIFI_LEADER_MAX];

/*
	CATS_SYS_PTR	pActSys;	///<セルアクターシステム
	CATS_RES_PTR	pActRes;	///<セルアクターリソース
	CLACT_WORK_PTR	pAct[ACT_MAX];		///<アクト
*/
	// OBJ関連
	CATS_SYS_PTR	csp;
	CATS_RES_PTR	crp;
	CATS_ACT_PTR	cap[ACT_MAX];

	// ボタンアニメ
	u8	btn_mode:1;
	u8	btn_id:7;			// OBJ = ID, BG = FRM
	u8	btn_pal1:4;
	u8	btn_pal2:4;
	u8	btn_seq;
	u8	btn_cnt;
	u8	btn_px;			// BGのみ
	u8	btn_py;
	u8	btn_sx;
	u8	btn_sy;

	int	next_seq;
	u16	page;
	u8	list_swap;
	u8	info_swap;

	CURSOR_MOVE_WORK * cmwk;	// カーソル移動ワーク
	u32	cm_page_change;			// カーソル移動でスクロールしたとき 0=なし 1=左 2=右

#ifdef PM_DEBUG
	u32	debugFlag;		// デバッグ用フラグ
#endif

}BTOWER_APP_WORK;

//=========================================================
//サブプロセスプロトタイプ
//=========================================================
static int BTowerApp_InitCommon(BTOWER_APP_WORK* wk);
static int BTowerApp_ReleaseCommon(BTOWER_APP_WORK* wk);

static void BTowerAppVramBankSet(void);
static void BTowerAppVBlank(void * work);
static int BTowerApp_KeyInScore(BTOWER_APP_WORK* wk);
static int BTowerApp_KeyInLeader(BTOWER_APP_WORK* wk);
static void BTowerAppBGLInit(BTOWER_APP_WORK* wk);
static void BTowerAppBGLRelease(BTOWER_APP_WORK* wk);
static void BTowerApp_2DGraInit(BTOWER_APP_WORK* wk);
static void BTowerApp_BmpWinAdd(BTOWER_APP_WORK* wk);
static void BTowerApp_BmpWinRelease(BTOWER_APP_WORK* wk);
static void BTowerApp_MsgManagerGet(BTOWER_APP_WORK* wk);
static void BTowerApp_MsgManagerRelease(BTOWER_APP_WORK* wk);
static void BTowerApp_MsgWriteScore(BTOWER_APP_WORK* wk);
static void BTowerApp_GetLeaderData(BTOWER_APP_WORK* wk);
static void BTowerApp_ReleaseLeaderData(BTOWER_APP_WORK* wk);

static void BTowerApp_MsgWriteLeader(BTOWER_APP_WORK* wk);
static void BTowerApp_WritePlayerList( BTOWER_APP_WORK * wk );
static void PlayerListPageWrite( BTOWER_APP_WORK * wk );
static void BTowerApp_WritePlayerInfo( BTOWER_APP_WORK * wk, u32 pos );
static void BTowerApp_PlayerAreaMsgWrite(BTOWER_APP_WORK* wk);
static void BTowerApp_PlayerMsgWrite(BTOWER_APP_WORK* wk);
static void BTowerApp_PlayerMsgClear(BTOWER_APP_WORK* wk);

static void BTowerApp_ActorInit(BTOWER_APP_WORK *wk);
static void BTowerApp_ActorRelease(BTOWER_APP_WORK *wk);
static void BTowerApp_ActorMain(BTOWER_APP_WORK *wk);
static void BTowerApp_ActorTrans(void);
static void Act_CursorChg(BTOWER_APP_WORK* wk,BOOL mode);
static void Act_CursorPosSet(BTOWER_APP_WORK* wk,u8 line,u8 side,u8 viewLine);

static BOOL ButtonAnmMain( BTOWER_APP_WORK * wk );
static void ButtonAnmSet( BTOWER_APP_WORK * wk, u32 objID );
static void RetButtonAnmSet( BTOWER_APP_WORK * wk );

static void LeaderCursorMoveInit( BTOWER_APP_WORK * wk );
static void LeaderCursorMoveExit( BTOWER_APP_WORK * wk );
static void LeaderSelCursorPut( BTOWER_APP_WORK * wk, int pos );
static void CursorMoveCallBack_Dummy( void * work, int now_pos, int old_pos );
static void LeaderCallBack_Move( void * work, int now_pos, int old_pos );
static void LeaderCallBack_Touch( void * work, int now_pos, int old_pos );



// ＯＢＪデータ
static const TCATS_OBJECT_ADD_PARAM_S ClaAddPrm[] =
{
	{	//「もどる」ボタンカーソル
		OBJ_RET_BUTTON_PX, OBJ_RET_BUTTON_PY, 0,
		OBJANM_RET_CURSOR, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_OBJ, PAL_ID_OBJ, CEL_ID_OBJ, ANM_ID_OBJ, CLA_H_NONE, CLA_H_NONE },
		0, 0
	},
	{	//「もどる」ボタン
		OBJ_RET_BUTTON_PX, OBJ_RET_BUTTON_PY, 0,
		OBJANM_RET_BUTTON, 10, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_OBJ, PAL_ID_OBJ, CEL_ID_OBJ, ANM_ID_OBJ, CLA_H_NONE, CLA_H_NONE },
		1, 0
	},
	{	// 左矢印
		OBJ_L_ARROW_PX, OBJ_ARROW_PY, 0,
		OBJANM_L_ARROW, 0, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_OBJ, PAL_ID_OBJ, CEL_ID_OBJ, ANM_ID_OBJ, CLA_H_NONE, CLA_H_NONE },
		0, 0
	},
	{	// 右矢印
		OBJ_R_ARROW_PX, OBJ_ARROW_PY, 0,
		OBJANM_R_ARROW, 10, 0, NNS_G2D_VRAM_TYPE_2DMAIN,
		{ CHR_ID_OBJ, PAL_ID_OBJ, CEL_ID_OBJ, ANM_ID_OBJ, CLA_H_NONE, CLA_H_NONE },
		0, 0
	},
};

static const TP_HIT_TBL EndHitTbl = { 164, 187, 193, 254 };		//「もどる」ボタンタッチ座標

// スクロール矢印のタッチ座標テーブル
static const RECT_HIT_TBL ListPageSelArrowHitTbl[] =
{
	{ 162, 189, 18, 45 },		// 左
	{ 162, 189, 50, 77 },		// 右
	{ RECT_HIT_END, 0, 0, 0 }
};



//--------------------------------------------------
///プログラムエリア
//----------------------------------------------------------------
/**
 *	@brief	バトルタワーアプリ プロセス初期化
 *	@param	proc	プロセスデータ
 *	@param	seq		シーケンス
 *
 *	@return	処理状況
 */
PROC_RESULT BTowerAppProc_Init( PROC *proc,int *seq)
{
	BTOWER_APP_WORK *wk = NULL;
	BTOWER_APP_PARAM * sp;

	sp = (BTOWER_APP_PARAM*)PROC_GetParentWork(proc);

	//ワークエリア取得
	HeapStatePush();


	//ヒープ作成
	sys_CreateHeap(HEAPID_BASE_APP,HEAPID_BTOWER_APP,0x20000);

	wk = PROC_AllocWork( proc,sizeof(BTOWER_APP_WORK),HEAPID_BTOWER_APP);
	memset(wk,0,sizeof(BTOWER_APP_WORK));

	//パラメータ引継ぎ
	wk->mainMode = sp->mainMode;
	wk->subMode = sp->subMode;
	wk->configSave = SaveData_GetConfig(sp->save);
	wk->frontierSave = SaveData_GetFrontier(sp->save);
	wk->scoreSave = SaveData_GetTowerScoreData(sp->save);
	wk->wifiSave = SaveData_GetTowerWifiData(sp->save);
//	wk->param.msg_spd		= CONFIG_GetMsgSpeed(sp);
//	wk->param.win_type		= CONFIG_GetWindowType(sp);

	wk->heapID = HEAPID_BTOWER_APP;

	// KeyRepeat設定
	sys_KeyRepeatSpeedSet( SYS_KEYREPEAT_SPEED_DEF, SYS_KEYREPEAT_WAIT_DEF );

#ifdef PM_DEBUG
	wk->debugFlag = sp->debugFlag;
#endif

	return PROC_RES_FINISH;
}

/**
 *	@brief	タワーアプリ プロセス終了
 *	@param	proc	プロセスデータ
 *	@param	seq		シーケンス
 *
 *	@return	処理状況
 */
PROC_RESULT BTowerAppProc_End( PROC *proc,int *seq)
{
	BTOWER_APP_WORK* wk = PROC_GetWork(proc);

	//ワークエリア解放
	PROC_FreeWork(proc);

	HeapStatePop();
	HeapStateCheck(wk->heapID);
	sys_DeleteHeap(wk->heapID);

	return PROC_RES_FINISH;
}


/***
 *	@brief	タワーアプリ　メインプロセス
 */
// メインシーケンス
enum {
	MAINSEQ_INIT = 0,			// 初期化
	MAINSEQ_START_FADE_SET,		// 開始フェードセット
	MAINSEQ_START_FADE_MAIN,	// 開始フェードメイン
	MAINSEQ_RESULT_MAIN,		// 成績画面メイン
	MAINSEQ_LEADER_MAIN,		// リーダー一覧メイン
	MAINSEQ_BUTTON_ANM,			// ボタンアニメ
	MAINSEQ_END_FADE_SET,		// 終了フェードセット
	MAINSEQ_END_FADE_MAIN,		// 終了フェードメイン
	MAINSEQ_END					// 終了
};

PROC_RESULT	BTowerAppProc_Main( PROC *proc,int* seq)
{
	BTOWER_APP_WORK * wk = PROC_GetWork(proc);

	switch( *seq ){
	case MAINSEQ_INIT:				// 初期化
		if( BTowerApp_InitCommon(wk) ){
			*seq = MAINSEQ_START_FADE_SET;
		}
		break;

	case MAINSEQ_START_FADE_SET:	// 開始フェードセット
		WIPE_SYS_Start(
			WIPE_PATTERN_WMS,
			WIPE_TYPE_FADEIN,
			WIPE_TYPE_FADEIN,0x0000,COMM_BRIGHTNESS_SYNC,1,wk->heapID );
		*seq = MAINSEQ_START_FADE_MAIN;
		break;

	case MAINSEQ_START_FADE_MAIN:	// 開始フェードメイン
		if( WIPE_SYS_EndCheck() ){
			if( wk->mainMode==0 ){
				*seq = MAINSEQ_RESULT_MAIN;
			}else{
				*seq = MAINSEQ_LEADER_MAIN;
			}
		}
		break;

	case MAINSEQ_RESULT_MAIN:		// 成績画面メイン
		*seq = BTowerApp_KeyInScore( wk );
		break;

	case MAINSEQ_LEADER_MAIN:		// リーダー一覧メイン
		*seq = BTowerApp_KeyInLeader( wk );
		break;

	case MAINSEQ_BUTTON_ANM:		// ボタンアニメ
		if( ButtonAnmMain( wk ) == FALSE ){
			*seq = wk->next_seq;
		}
		break;

	case MAINSEQ_END_FADE_SET:		// 終了フェードセット
		WIPE_SYS_Start(
			WIPE_PATTERN_WMS,
			WIPE_TYPE_FADEOUT,
			WIPE_TYPE_FADEOUT,0x0000,COMM_BRIGHTNESS_SYNC,1,wk->heapID );
		*seq = MAINSEQ_END_FADE_MAIN;
		break;

	case MAINSEQ_END_FADE_MAIN:		// 終了フェードメイン
		if( WIPE_SYS_EndCheck() ){
			*seq = MAINSEQ_END;
		}
		break;

	case MAINSEQ_END:				// 終了
		if( BTowerApp_ReleaseCommon(wk) ){
			return PROC_RES_FINISH;
		}
		break;
	}

	if( *seq >= MAINSEQ_START_FADE_SET && *seq <= MAINSEQ_END_FADE_MAIN ){
		BTowerApp_ActorMain(wk);
	}

	return PROC_RES_CONTINUE;
}

/**
 *	@brief	画面初期化
 */
static int BTowerApp_InitCommon(BTOWER_APP_WORK* wk)
{
	switch(wk->seq){
	case 0:
		sys_VBlankFuncChange(NULL,NULL);
		sys_HBlankIntrStop();

		GF_Disp_GX_VisibleControlInit();
		GF_Disp_GXS_VisibleControlInit();
		GX_SetVisiblePlane(0);
		GXS_SetVisiblePlane(0);
		// サブ画面をメインに
		GX_SetDispSelect( GX_DISP_SELECT_SUB_MAIN );

		//Bankセット
		BTowerAppVramBankSet();
		WIPE_ResetWndMask(WIPE_DISP_MAIN);
		WIPE_ResetWndMask(WIPE_DISP_SUB);

		//BGLセット
		BTowerAppBGLInit(wk);
		break;
	case 1:
		//2Dリソース取得
		BTowerApp_2DGraInit(wk);
		//メッセージリソース取得
		BTowerApp_MsgManagerGet(wk);
		break;

	case 2:
		//アクター初期化
		BTowerApp_ActorInit(wk);
		break;

	case 3:
		//Bmpウィンドウ取得
		BTowerApp_BmpWinAdd(wk);
		if(wk->mainMode == 0){
			//メッセージ初期描画
			BTowerApp_MsgWriteScore(wk);
		}else{
			//リーダーデータ取得
			BTowerApp_GetLeaderData(wk);
			//初期メッセージ描画
			BTowerApp_MsgWriteLeader(wk);
			// プレイヤーのエリアメッセージ
			BTowerApp_PlayerAreaMsgWrite(wk);
			// カーソル移動初期化
			LeaderCursorMoveInit( wk );
		}
		break;

	case 4:
		sys_VBlankFuncChange(BTowerAppVBlank,wk);
		wk->seq = 0;
		return TRUE;
	}
	wk->seq++;
	return FALSE;
}

/**
 *	@brief	画面解放
 */
static int BTowerApp_ReleaseCommon(BTOWER_APP_WORK* wk)
{
	switch(wk->seq){
	case 0:
		if( wk->mainMode != 0 ){
			LeaderCursorMoveExit( wk );
			BTowerApp_ReleaseLeaderData( wk );
		}
		//アクター解放
		BTowerApp_ActorRelease(wk);
		//Bmpウィンドウ解放
		BTowerApp_BmpWinRelease(wk);
		//メッセージリソース解放
		BTowerApp_MsgManagerRelease(wk);
		//2Dリソース解放
		BTowerAppBGLRelease(wk);
		break;
	case 1:
		sys_VBlankFuncChange(NULL,NULL);
		sys_HBlankIntrStop();

		GF_Disp_GX_VisibleControlInit();
		GF_Disp_GXS_VisibleControlInit();
		GX_SetVisiblePlane(0);
		GXS_SetVisiblePlane(0);
		wk->seq = 0;
		return TRUE;
	}
	wk->seq++;
	return FALSE;
}

/**
 *	@brief	タワーアプリ画面VramBankセット
 */
static void BTowerAppVramBankSet(void)
{
	GF_BGL_DISPVRAM vramSetTable = {
		GX_VRAM_BG_128_A,				// メイン2DエンジンのBG
		GX_VRAM_BGEXTPLTT_NONE,			// メイン2DエンジンのBG拡張パレット
		GX_VRAM_SUB_BG_128_C,			// サブ2DエンジンのBG
		GX_VRAM_SUB_BGEXTPLTT_NONE,		// サブ2DエンジンのBG拡張パレット
		GX_VRAM_OBJ_64_E,				// メイン2DエンジンのOBJ
		GX_VRAM_OBJEXTPLTT_NONE,		// メイン2DエンジンのOBJ拡張パレット
		GX_VRAM_SUB_OBJ_16_I,			// サブ2DエンジンのOBJ
		GX_VRAM_SUB_OBJEXTPLTT_NONE,	// サブ2DエンジンのOBJ拡張パレット
		GX_VRAM_TEX_NONE,				// テクスチャイメージスロット
		GX_VRAM_TEXPLTT_NONE			// テクスチャパレットスロット
	};

	GF_Disp_SetBank( &vramSetTable );
}

/**
 *	@brief	タワーアプリ画面VBlank
 */
static void BTowerAppVBlank(void * work)
{
	BTOWER_APP_WORK* wk = work;

	BTowerApp_ActorTrans();

//	NNS_GfdDoVramTransfer();	//VRam転送マネージャ実行
//	CLACT_VBlankSys();	//OAMマネージャリセット
	GF_BGL_VBlankFunc( wk->bgl );
	OS_SetIrqCheckFlag( OS_IE_V_BLANK);
}

/**
 *	@brief	キー取得
 */
static int BTowerApp_KeyInScore(BTOWER_APP_WORK* wk)
{
	if( GF_TP_SingleHitTrg( &EndHitTbl ) == TRUE ||
		( sys.trg & (PAD_BUTTON_DECIDE|PAD_BUTTON_CANCEL) ) ){
		Snd_SePlay( SEQ_SE_DP_DECIDE );
		RetButtonAnmSet( wk );
		wk->next_seq = MAINSEQ_END_FADE_SET;
		return MAINSEQ_BUTTON_ANM;
	}

/*
	if( sys.trg & PAD_BUTTON_CANCEL ){
		Snd_SePlay( SEQ_SE_DP_DECIDE );
		return MAINSEQ_END_FADE_SET;
	}
*/

	return MAINSEQ_RESULT_MAIN;
}

static inline u8 line_up(BTOWER_APP_WORK* wk)
{
	if(wk->line == 0){
		return 0;
	}
	--wk->line;
	if(wk->viewLine == 0){
		--wk->upLine;
		return 1;
	}
	--wk->viewLine;
	return 1;
}

static inline u8 line_down(BTOWER_APP_WORK* wk)
{
	if(wk->line >= LINE_RET){
		return 0;
	}
	++wk->line;
	if(wk->viewLine > 1){
		++wk->upLine;
		return 1;
	}
	++wk->viewLine;
	return 1;
}

/**
 *	@brief	キー取得
 */
static int BTowerApp_KeyInLeader(BTOWER_APP_WORK* wk)
{
	u32	ret = CURSORMOVE_Main(wk->cmwk);

	switch( ret ){
	case PLAYER_PUT_MAX:
	case CURSORMOVE_CANCEL:			// キャンセル
		Snd_SePlay( SEQ_SE_DP_DECIDE );
		RetButtonAnmSet( wk );
		wk->next_seq = MAINSEQ_END_FADE_SET;
		return MAINSEQ_BUTTON_ANM;

	case CURSORMOVE_CURSOR_MOVE:	// 移動
		Snd_SePlay( SEQ_SE_DP_SELECT );
		if( wk->cm_page_change == 1 ){
			ButtonAnmSet( wk, ACT_L_ARROW );
			wk->next_seq = MAINSEQ_LEADER_MAIN;
			return MAINSEQ_BUTTON_ANM;
		}else if( wk->cm_page_change == 2 ){
			ButtonAnmSet( wk, ACT_R_ARROW );
			wk->next_seq = MAINSEQ_LEADER_MAIN;
			return MAINSEQ_BUTTON_ANM;
		}
		break;

	case CURSORMOVE_CURSOR_ON:		// カーソル表示
	case CURSORMOVE_NONE:			// 動作なし
		break;

	default:
		if( GF_TP_GetTrg() == TRUE ){
			Snd_SePlay( SEQ_SE_DP_SELECT );
		}
		break;
	}

	// スクロール矢印
	switch( GF_TP_RectHitTrg( ListPageSelArrowHitTbl ) ){
	case 0:
		if( wk->page != 0 ){
			wk->page--;
		}else{
			wk->page = PLAYER_LIST_PAGE_MAX;
		}
		Snd_SePlay( SEQ_SE_DP_SELECT78 );
		BTowerApp_WritePlayerList( wk );
		BTowerApp_WritePlayerInfo( wk, wk->page*PLAYER_PUT_MAX+CURSORMOVE_PosGet(wk->cmwk) );
		PlayerListPageWrite( wk );
		ButtonAnmSet( wk, ACT_L_ARROW );
		wk->next_seq = MAINSEQ_LEADER_MAIN;
		return MAINSEQ_BUTTON_ANM;

	case 1:
		if( wk->page < PLAYER_LIST_PAGE_MAX ){
			wk->page++;
		}else{
			wk->page = 0;
		}
		Snd_SePlay( SEQ_SE_DP_SELECT78 );
		BTowerApp_WritePlayerList( wk );
		BTowerApp_WritePlayerInfo( wk, wk->page*PLAYER_PUT_MAX+CURSORMOVE_PosGet(wk->cmwk) );
		PlayerListPageWrite( wk );
		ButtonAnmSet( wk, ACT_R_ARROW );
		wk->next_seq = MAINSEQ_LEADER_MAIN;
		return MAINSEQ_BUTTON_ANM;
	}

	return MAINSEQ_LEADER_MAIN;
}

/**
 *	@brief	タワー画面BGLシステム初期化
 */
static void BTowerAppBGLInit(BTOWER_APP_WORK* wk)
{
	int i,frame;

	wk->bgl = GF_BGL_BglIniAlloc(wk->heapID);

	{	//BG SYSTEM
		GF_BGL_SYS_HEADER BGsys_data = {
			GX_DISPMODE_GRAPHICS,GX_BGMODE_0,GX_BGMODE_0,GX_BG0_AS_2D
		};
		GF_BGL_InitBG(&BGsys_data);
	}

	{	// MAIN BG0 最上位テキスト面
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xf800, GX_BG_CHARBASE_0x10000, GX_BG_EXTPLTT_01,
			0, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, GF_BGL_FRAME0_M, &TextBgCntDat, GF_BGL_MODE_TEXT );
		GF_BGL_ClearCharSet( GF_BGL_FRAME0_M, 32, 0, wk->heapID );
		GF_BGL_ScrClear( wk->bgl, GF_BGL_FRAME0_M );
	}
	{	// MAIN BG1 上位BG面
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xf000, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01,
			1, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, GF_BGL_FRAME1_M, &TextBgCntDat, GF_BGL_MODE_TEXT );
	}

	{	// SUB BG0 最上位テキスト面
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xf800, GX_BG_CHARBASE_0x10000, GX_BG_EXTPLTT_01,
			0, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, GF_BGL_FRAME0_S, &TextBgCntDat, GF_BGL_MODE_TEXT );
		GF_BGL_ClearCharSet( GF_BGL_FRAME0_S, 32, 0, wk->heapID );
		GF_BGL_ScrClear( wk->bgl, GF_BGL_FRAME0_S );
	}
	{	// SUB BG1 上位BG面
		GF_BGL_BGCNT_HEADER TextBgCntDat = {
			0, 0, 0x800, 0, GF_BGL_SCRSIZ_256x256, GX_BG_COLORMODE_16,
			GX_BG_SCRBASE_0xf000, GX_BG_CHARBASE_0x00000, GX_BG_EXTPLTT_01,
			1, 0, 0, FALSE
		};
		GF_BGL_BGControlSet( wk->bgl, GF_BGL_FRAME1_S, &TextBgCntDat, GF_BGL_MODE_TEXT );
	}
}

/**
 *	@brief	タワー画面BGLシステム破棄
 */
static void BTowerAppBGLRelease(BTOWER_APP_WORK* wk)
{
	GF_BGL_BGControlExit( wk->bgl, GF_BGL_FRAME1_S );
	GF_BGL_BGControlExit( wk->bgl, GF_BGL_FRAME0_S );
//	GF_BGL_BGControlExit( wk->bgl, GF_BGL_FRAME2_M );
	GF_BGL_BGControlExit( wk->bgl, GF_BGL_FRAME1_M );
	GF_BGL_BGControlExit( wk->bgl, GF_BGL_FRAME0_M );

	sys_FreeMemoryEz(wk->bgl);
}

/**
 *	@brief	タワーアプリ　2Dリソース初期化
 */
static void BTowerApp_2DGraInit(BTOWER_APP_WORK* wk)
{
	ARCHANDLE * ah;

	if( wk->mainMode == 0 ){
		// メイン
		ah = ArchiveDataHandleOpen( ARC_BTOWER_APP, wk->heapID );

		ArcUtil_HDL_BgCharSet(
			ah, NARC_btower_bf_leader_bg_d_lz_NCGR, wk->bgl, GF_BGL_FRAME1_M, 0, 0, 1, wk->heapID );
		ArcUtil_HDL_PalSet(
			ah, NARC_btower_bf_leader_bg_d_NCLR, PALTYPE_MAIN_BG, 0, 0x20, wk->heapID );
		ArcUtil_HDL_ScrnSet(
			ah, NARC_btower_bf_leader_bg2_d_lz_NSCR, wk->bgl, GF_BGL_FRAME1_M, 0, 0, 1, wk->heapID );

		ArchiveDataHandleClose( ah );

		// サブ
		ah = ArchiveDataHandleOpen( ARC_FRONTIER_BG, wk->heapID );

		ArcUtil_HDL_BgCharSet(
			ah, BF_U_NCGR_BIN, wk->bgl, GF_BGL_FRAME1_S, 0, 0, 1, wk->heapID );
		ArcUtil_HDL_PalSet(
			ah, BF_U_NCLR, PALTYPE_SUB_BG, 0, 0x20, wk->heapID );
		ArcUtil_HDL_ScrnSet(
			ah, BF_U_NSCR_BIN, wk->bgl, GF_BGL_FRAME1_S, 0, 0, 1, wk->heapID );

		ArchiveDataHandleClose( ah );
	}else{
		ah = ArchiveDataHandleOpen( ARC_BTOWER_APP, wk->heapID );

		// メイン
		ArcUtil_HDL_BgCharSet(
			ah, NARC_btower_bf_leader_bg_d_lz_NCGR, wk->bgl, GF_BGL_FRAME1_M, 0, 0, 1, wk->heapID );
		ArcUtil_HDL_PalSet(
			ah, NARC_btower_bf_leader_bg_d_NCLR, PALTYPE_MAIN_BG, 0, 0x20, wk->heapID );
		ArcUtil_HDL_ScrnSet(
			ah, NARC_btower_bf_leader_bg_d_lz_NSCR, wk->bgl, GF_BGL_FRAME1_M, 0, 0, 1, wk->heapID );

		// サブ
		ArcUtil_HDL_BgCharSet(
			ah, NARC_btower_bf_leader_bg_u_lz_NCGR, wk->bgl, GF_BGL_FRAME1_S, 0, 0, 1, wk->heapID );
		ArcUtil_HDL_PalSet(
			ah, NARC_btower_bf_leader_bg_u_NCLR, PALTYPE_SUB_BG, 0, 0x20, wk->heapID );
		ArcUtil_HDL_ScrnSet(
			ah, NARC_btower_bf_leader_bg_u_lz_NSCR, wk->bgl, GF_BGL_FRAME1_S, 0, 0, 1, wk->heapID );

		ArchiveDataHandleClose( ah );
	}

}

/**
 *	@brief	タワーアプリ　BMPWIN初期化
 */
static void BTowerApp_BmpWinAdd(BTOWER_APP_WORK* wk)
{
	int i;

	// 成績画面
	static const BMPWIN_DAT bmp01[] =
	{
		{	//「もどる」
			BMP_RET_FRM, BMP_RET_PX, BMP_RET_PY,
			BMP_RET_SX, BMP_RET_SY, BMP_RET_PAL, BMP_RET_CGX
		},
		{	// 成績タイトル
			BMPS_TITLE_FRM, BMPS_TITLE_PX, BMPS_TITLE_PY,
			BMPS_TITLE_SX, BMPS_TITLE_SY, BMPS_TITLE_PAL, BMPS_TITLE_CGX
		},
		{	//「げんざいのきろく」
			BMPS_ST01_FRM, BMPS_ST01_PX, BMPS_ST01_PY,
			BMPS_ST01_SX, BMPS_ST01_SY, BMPS_ST01_PAL, BMPS_ST01_CGX
		},
		{	//「Wi-Fiのきろく」
			BMPS_ST02_FRM, BMPS_ST02_PX, BMPS_ST02_PY,
			BMPS_ST02_SX, BMPS_ST02_SY, BMPS_ST02_PAL, BMPS_ST02_CGX
		},
		{	//「ランク」
			BMPS_RANK_FRM, BMPS_RANK_PX, BMPS_RANK_PY,
			BMPS_RANK_SX, BMPS_RANK_SY, BMPS_RANK_PAL, BMPS_RANK_CGX
		},
		{	// ランク
			BMPS_RANK_NUM_FRM, BMPS_RANK_NUM_PX, BMPS_RANK_NUM_PY,
			BMPS_RANK_NUM_SX, BMPS_RANK_NUM_SY, BMPS_RANK_NUM_PAL, BMPS_RANK_NUM_CGX
		},
		{	//「ぜんかい」
			BMPS_OLD_FRM, BMPS_OLD_PX, BMPS_OLD_PY,
			BMPS_OLD_SX, BMPS_OLD_SY, BMPS_OLD_PAL, BMPS_OLD_CGX
		},
		{	// 前回の連勝数
			BMPS_OLD_WIN_FRM, BMPS_OLD_WIN_PX, BMPS_OLD_WIN_PY,
			BMPS_OLD_WIN_SX, BMPS_OLD_WIN_SY, BMPS_OLD_WIN_PAL, BMPS_OLD_WIN_CGX
		},
		{	//「れんしょう」（前回）
			BMPS_OLD_STR_FRM, BMPS_OLD_STR_PX, BMPS_OLD_STR_PY,
			BMPS_OLD_STR_SX, BMPS_OLD_STR_SY, BMPS_OLD_STR_PAL, BMPS_OLD_STR_CGX
		},
		{	//「さいこう」
			BMPS_BST_FRM, BMPS_BST_PX, BMPS_BST_PY,
			BMPS_BST_SX, BMPS_BST_SY, BMPS_BST_PAL, BMPS_BST_CGX
		},
		{	// 最高連勝数
			BMPS_BST_WIN_FRM, BMPS_BST_WIN_PX, BMPS_BST_WIN_PY,
			BMPS_BST_WIN_SX, BMPS_BST_WIN_SY, BMPS_BST_WIN_PAL, BMPS_BST_WIN_CGX
		},
		{	//「れんしょう」（最高）
			BMPS_BST_STR_FRM, BMPS_BST_STR_PX, BMPS_BST_STR_PY,
			BMPS_BST_STR_SX, BMPS_BST_STR_SY, BMPS_BST_STR_PAL, BMPS_BST_STR_CGX
		},
	};
	// リーダー一覧
	static const BMPWIN_DAT bmp02[] =
	{
		{	//「もどる」
			BMP_RET_FRM, BMP_RET_PX, BMP_RET_PY,
			BMP_RET_SX, BMP_RET_SY, BMP_RET_PAL, BMP_RET_CGX
		},
		{	//「ランク」
			BMPL_RANK_FRM, BMPL_RANK_PX, BMPL_RANK_PY,
			BMPL_RANK_SX, BMPL_RANK_SY, BMPL_RANK_PAL, BMPL_RANK_CGX
		},
		{	//「バトルルーム」
			BMPL_ROOM_FRM, BMPL_ROOM_PX, BMPL_ROOM_PY,
			BMPL_ROOM_SX, BMPL_ROOM_SY, BMPL_ROOM_PAL, BMPL_ROOM_CGX
		},
		{	// タイトル
			BMPL_TITLE_FRM, BMPL_TITLE_PX, BMPL_TITLE_PY,
			BMPL_TITLE_SX, BMPL_TITLE_SY, BMPL_TITLE_PAL, BMPL_TITLE_CGX
		},
		{	// ページ
			BMPL_PAGE_FRM, BMPL_PAGE_PX, BMPL_PAGE_PY,
			BMPL_PAGE_SX, BMPL_PAGE_SY, BMPL_PAGE_PAL, BMPL_PAGE_CGX
		},

		{	// リーダー情報
			BMPL_INFO_FRM, BMPL_INFO_PX, BMPL_INFO_PY,
			BMPL_INFO_SX, BMPL_INFO_SY, BMPL_INFO_PAL, BMPL_INFO_CGX
		},
		{	// 住所
			BMPL_ADRS_FRM, BMPL_ADRS_PX, BMPL_ADRS_PY,
			BMPL_ADRS_SX, BMPL_ADRS_SY, BMPL_ADRS_PAL, BMPL_ADRS_CGX
		},
		{	// 挨拶
			BMPL_COMM_FRM, BMPL_COMM_PX, BMPL_COMM_PY,
			BMPL_COMM_SX, BMPL_COMM_SY, BMPL_COMM_PAL, BMPL_COMM_CGX
		},
		{	// リーダー情報（スワップ）
			BMPL_INFO_FRM, BMPL_INFO_PX, BMPL_INFO_PY,
			BMPL_INFO_SX, BMPL_INFO_SY, BMPL_INFO_PAL, BMPL_INFO_S_CGX
		},
		{	// 住所（スワップ）
			BMPL_ADRS_FRM, BMPL_ADRS_PX, BMPL_ADRS_PY,
			BMPL_ADRS_SX, BMPL_ADRS_SY, BMPL_ADRS_PAL, BMPL_ADRS_S_CGX
		},
		{	// 挨拶（スワップ）
			BMPL_COMM_FRM, BMPL_COMM_PX, BMPL_COMM_PY,
			BMPL_COMM_SX, BMPL_COMM_SY, BMPL_COMM_PAL, BMPL_COMM_S_CGX
		},

		{	// 名前
			BMPL_NAME_FRM, BMPL_NAME01_PX, BMPL_NAME01_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME01_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME02_PX, BMPL_NAME02_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME02_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME03_PX, BMPL_NAME03_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME03_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME04_PX, BMPL_NAME04_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME04_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME05_PX, BMPL_NAME05_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME05_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME06_PX, BMPL_NAME06_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME06_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME07_PX, BMPL_NAME07_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME07_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME08_PX, BMPL_NAME08_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME08_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME09_PX, BMPL_NAME09_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME09_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME0A_PX, BMPL_NAME0A_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME0A_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME0B_PX, BMPL_NAME0B_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME0B_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME0C_PX, BMPL_NAME0C_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME0C_CGX
		},
		{	// 名前（スワップ）
			BMPL_NAME_FRM, BMPL_NAME01_PX, BMPL_NAME01_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME11_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME02_PX, BMPL_NAME02_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME12_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME03_PX, BMPL_NAME03_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME13_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME04_PX, BMPL_NAME04_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME14_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME05_PX, BMPL_NAME05_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME15_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME06_PX, BMPL_NAME06_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME16_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME07_PX, BMPL_NAME07_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME17_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME08_PX, BMPL_NAME08_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME18_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME09_PX, BMPL_NAME09_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME19_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME0A_PX, BMPL_NAME0A_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME1A_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME0B_PX, BMPL_NAME0B_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME1B_CGX
		},
		{
			BMPL_NAME_FRM, BMPL_NAME0C_PX, BMPL_NAME0C_PY,
			BMPL_NAME_SX, BMPL_NAME_SY, BMPL_NAME_PAL, BMPL_NAME1C_CGX
		},
	};

	// ウィンドウ作成
	if( wk->mainMode == 0 ){
		for( i=0; i<WINS_MAX; i++ ){
			GF_BGL_BmpWinAddEx( wk->bgl, &wk->win[i], &bmp01[i] );
//			GF_BGL_BmpWinDataFill( &wk->win[i], APP_WINCLR_COL(FBMP_COL_NULL) );
		}
	}else{
		for( i=0; i<WINL_MAX; i++ ){
			GF_BGL_BmpWinAddEx( wk->bgl, &wk->win[i], &bmp02[i] );
			GF_BGL_BmpWinDataFill( &wk->win[i], APP_WINCLR_COL(FBMP_COL_NULL) );
		}
	}

	// タッチフォント読み込み
	FontProc_LoadFont( FONT_TOUCH, wk->heapID );

	// システム用フォントパレット転送
	SystemFontPaletteLoad( PALTYPE_MAIN_BG, FONT_SYS_PAL*32, wk->heapID );
	SystemFontPaletteLoad( PALTYPE_SUB_BG, FONT_SYS_PAL*32, wk->heapID );
}

/**
 *	@brief	タワーアプリ　BMPウィンドウ解放
 */
static void BTowerApp_BmpWinRelease(BTOWER_APP_WORK* wk)
{
	int i,size;

	// タッチフォント削除
	FontProc_UnloadFont( FONT_TOUCH );

	if(wk->mainMode == 0){
		size = WINS_MAX;
	}else{
		size = WINL_MAX;
	}
	for(i = 0;i < size;i++){
		GF_BGL_BmpWinOff(&wk->win[i]);
		GF_BGL_BmpWinDel(&wk->win[i]);
	}
}

/**
 *	@brief	タワーアプリ　メッセージマネージャ初期化
 */
static void BTowerApp_MsgManagerGet(BTOWER_APP_WORK* wk)
{
	wk->msgDat.pMan = MSGMAN_Create(MSGMAN_TYPE_NORMAL,ARC_MSG,
			NARC_msg_btower_app_dat,wk->heapID);

//	wk->msgDat.wset = WORDSET_CreateEx(2,WORDSET_BTOWER_APP_BUFLEN,wk->heapID);
	wk->msgDat.wset = WORDSET_Create( wk->heapID );

	//デフォルト文字列取得
	wk->msgDat.tmp = STRBUF_Create(WORDSET_BTOWER_APP_BUFLEN,wk->heapID);

	//プレイヤーデフォルト名展開
	wk->msgDat.def_name[0] = MSGMAN_AllocString(wk->msgDat.pMan,msg_def_player_name01);
	wk->msgDat.def_name[1] = MSGMAN_AllocString(wk->msgDat.pMan,msg_def_player_name02);
}

/**
 *	@brief	タワーアプリ　メッセージマネージャ解放
 */
static void BTowerApp_MsgManagerRelease(BTOWER_APP_WORK* wk)
{
	STRBUF_Delete(wk->msgDat.def_name[1]);
	STRBUF_Delete(wk->msgDat.def_name[0]);

	STRBUF_Delete(wk->msgDat.tmp);

	WORDSET_Delete(wk->msgDat.wset);
	MSGMAN_Delete(wk->msgDat.pMan);
}

//--------------------------------------------------------------------------------------------
/**
 * 文字列表示（バッファ指定）
 *
 * @param	win		BMPWIN
 * @param	str		文字列バッファ
 * @param	x		表示基準Ｘ座標
 * @param	y		表示基準Ｙ座標
 * @param	fnt		フォント
 * @param	col		カラー
 * @param	mode	表示モード
 *
 * @return	none
 *
 * @li	mode = STRPRINT_MODE_LEFT	: 左詰
 * @li	mode = STRPRINT_MODE_RIGHT	: 右詰
 * @li	mode = STRPRINT_MODE_CENTER	: 中央
 */
//--------------------------------------------------------------------------------------------
static void StrPrintCore(
				GF_BGL_BMPWIN * win, STRBUF * str,
				u32 x, u32 y, FONT_TYPE fnt, GF_PRINTCOLOR col, u32 mode )
{
	if( mode == STRPRINT_MODE_RIGHT ){
		x -= FontProc_GetPrintStrWidth( fnt, str, 0 );
	}else if( mode == STRPRINT_MODE_CENTER ){
		x -= ( FontProc_GetPrintStrWidth( fnt, str, 0 ) / 2 );
	}
	GF_STR_PrintColor( win, fnt, str, x, y, MSG_NO_PUT, col, NULL );
}

//--------------------------------------------------------------------------------------------
/**
 * 文字列表示（固定文字列）
 *
 * @param	wk		成績画面ワーク
 * @param	winID	BMPWIN ID
 * @param	msgID	文字列ＩＤ
 * @param	x		表示基準Ｘ座標
 * @param	y		表示基準Ｙ座標
 * @param	fnt		フォント
 * @param	col		カラー
 * @param	mode	表示モード
 *
 * @return	none
 *
 * @li	mode = STRPRINT_MODE_LEFT	: 左詰
 * @li	mode = STRPRINT_MODE_RIGHT	: 右詰
 * @li	mode = STRPRINT_MODE_CENTER	: 中央
 */
//--------------------------------------------------------------------------------------------
static void StrPrint(
				BTOWER_APP_WORK * wk,
				u32 winID, u32 msgID, u32 x, u32 y, FONT_TYPE fnt, GF_PRINTCOLOR col, u32 mode )
{
	STRBUF * str = MSGMAN_AllocString( wk->msgDat.pMan, msgID );

	StrPrintCore( &wk->win[winID], str, x, y, fnt, col, mode );

	STRBUF_Delete( str );
}

//--------------------------------------------------------------------------------------------
/**
 * 文字列表示（可変文字列）
 *
 * @param	wk		成績画面ワーク
 * @param	winID	BMPWIN ID
 * @param	msgID	文字列ＩＤ
 * @param	x		表示基準Ｘ座標
 * @param	y		表示基準Ｙ座標
 * @param	fnt		フォント
 * @param	col		カラー
 * @param	mode	表示モード
 *
 * @return	none
 *
 * @li	mode = STRPRINT_MODE_LEFT	: 左詰
 * @li	mode = STRPRINT_MODE_RIGHT	: 右詰
 * @li	mode = STRPRINT_MODE_CENTER	: 中央
 */
//--------------------------------------------------------------------------------------------
static void ExStrPrint(
				BTOWER_APP_WORK * wk,
				u32 winID, u32 msgID, u32 x, u32 y, FONT_TYPE fnt, GF_PRINTCOLOR col, u32 mode )
{
	STRBUF * str = MSGMAN_AllocString( wk->msgDat.pMan, msgID );

	WORDSET_ExpandStr( wk->msgDat.wset, wk->msgDat.tmp, str );

	StrPrintCore( &wk->win[winID], wk->msgDat.tmp, x, y, fnt, col, mode );

	STRBUF_Delete( str );
}

//--------------------------------------------------------------------------------------------
/**
 * 「もどる」表示
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void RetButtonStrPut( BTOWER_APP_WORK * wk )
{
	//「もどる」は共通のBMPWINに書く
	StrPrint(
		wk, 0, msg_btwr_leader_return,
		GF_BGL_BmpWinGet_SizeX(&wk->win[0])*8/2,
		0,
		FONT_TOUCH, FCOL_TOUCH, STRPRINT_MODE_CENTER );
}

/**
 *	成績モニタ画面文字列描画
 */
static void BTowerApp_MsgWriteScore(BTOWER_APP_WORK* wk)
{
	u32	i;

	for( i=0; i<WINS_MAX; i++ ){
		GF_BGL_BmpWinDataFill( &wk->win[i], 0 );
	}

	//「もどる」
	RetButtonStrPut( wk );

	// タイトル
	StrPrint(
		wk, WINS_TITLE, msg_btwr_score_t03,
		GF_BGL_BmpWinGet_SizeX(&wk->win[WINS_TITLE])*8/2,
		0,
		FONT_SYSTEM, FCOL_N_WHITE, STRPRINT_MODE_CENTER );

	//「げんざいのきろく」
	StrPrint(
		wk, WINS_ST01, msg_btwr_score_s03,
		0, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	//「Wi-Fiのきろく」
	StrPrint(
		wk, WINS_ST02, msg_btwr_score_s06,
		0, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	//「ランク」
	StrPrint(
		wk, WINS_RANK, msg_btwr_score_r04,
		0, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	//「ぜんかい」
	if( TowerScoreData_SetFlags(wk->scoreSave,BTWR_SFLAG_WIFI_RECORD,BTWR_DATA_get) == 0 ){
		StrPrint(
			wk, WINS_OLD, msg_btwr_score_r01,
			0, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );
	//「げんざい」
	}else{
		StrPrint(
			wk, WINS_OLD, msg_btwr_score_r02,
			0, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );
	}

	//「さいこう」
	StrPrint(
		wk, WINS_BST, msg_btwr_score_r03,
		0, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	//「れんしょう」（前回）
	StrPrint(
		wk, WINS_OLD_STR, msg_btwr_score_r08,
		GF_BGL_BmpWinGet_SizeX(&wk->win[WINS_OLD_STR])*8,
		0,
		FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	//「れんしょう」（最高）
	StrPrint(
		wk, WINS_BST_STR, msg_btwr_score_r08,
		GF_BGL_BmpWinGet_SizeX(&wk->win[WINS_BST_STR])*8,
		0,
		FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	// ランク
	WORDSET_RegisterNumber(
		wk->msgDat.wset, 0,
		TowerScoreData_SetWifiRank(wk->scoreSave,BTWR_DATA_get),
		2, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	ExStrPrint(
		wk, WINS_RANK_NUM, msg_btwr_score_r06,
		GF_BGL_BmpWinGet_SizeX(&wk->win[WINS_RANK_NUM])*8,
		0,
		FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	// 前回の連勝数
	WORDSET_RegisterNumber(
		wk->msgDat.wset, 0,
		FrontierRecord_Get(wk->frontierSave,FRID_TOWER_WIFI_DL_RENSHOU_CNT,FRONTIER_RECORD_NOT_FRIEND),
		4, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	ExStrPrint(
		wk, WINS_OLD_WIN, msg_btwr_score_r07,
		GF_BGL_BmpWinGet_SizeX(&wk->win[WINS_OLD_WIN])*8,
		0,
		FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	// 最高連勝数
	WORDSET_RegisterNumber(
		wk->msgDat.wset, 0,
		FrontierRecord_Get(wk->frontierSave,FRID_TOWER_WIFI_DL_RENSHOU,FRONTIER_RECORD_NOT_FRIEND),
		4, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	ExStrPrint(
		wk, WINS_BST_WIN, msg_btwr_score_r07,
		GF_BGL_BmpWinGet_SizeX(&wk->win[WINS_BST_WIN])*8,
		0,
		FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	for( i=0; i<WINS_MAX; i++ ){
		GF_BGL_BmpWinOnVReq( &wk->win[i] );
	}
}

/**
 *	@brief	歴代リーダーデータ取得
 */
static void BTowerApp_GetLeaderData(BTOWER_APP_WORK* wk)
{
	B_TOWER_LEADER_DATA* bp;
	LEADER_DATA* lp;
	int i;

	//まずはリーダーセーブデータを取得
	bp = TowerWifiData_GetLeaderDataAlloc( wk->wifiSave, wk->heapID );

	for( i=0; i<BTOWER_STOCK_WIFI_LEADER_MAX; i++ ){
		lp = &wk->leader[i];

		lp->sex = bp[i].gender;
		lp->country = bp[i].country_code;
		lp->area = bp[i].address;
		lp->ngname_f = bp[i].ngname_f;

		MI_CpuCopy8( bp[i].leader_word, &lp->msg, 8 );

		//プレイヤー名用STRBUFオブジェクト領域確保
		lp->name = STRBUF_Create( BUFLEN_PERSON_NAME, wk->heapID );

#ifdef PM_DEBUG
		if( wk->debugFlag == 1 ){
			STRBUF_Copy( lp->name, wk->msgDat.def_name[lp->sex] );
		}else{
			//もしもNGネームならデフォルト名で表示する
			if( lp->ngname_f ){
				STRBUF_Copy( lp->name, wk->msgDat.def_name[lp->sex] );
			}else{
				STRBUF_SetStringCode( lp->name, bp[i].name );
			}
		}
#else
		//もしもNGネームならデフォルト名で表示する
		if( lp->ngname_f ){
			STRBUF_Copy( lp->name, wk->msgDat.def_name[lp->sex] );
		}else{
			STRBUF_SetStringCode( lp->name, bp[i].name );
		}
#endif

	}

	//コピーしたらもう要らないので解放
	sys_FreeMemoryEz( bp );
}

/**
 *	@brief	歴代リーダーデータ解放
 */
static void BTowerApp_ReleaseLeaderData(BTOWER_APP_WORK * wk)
{
	int	i;

	for( i=0; i<BTOWER_STOCK_WIFI_LEADER_MAX; i++ ){
		STRBUF_Delete( wk->leader[i].name );
	}
}

/**
 *	@brief	歴代リーダー画面　プレイヤーリスト描画
 */
static void BTowerApp_WritePlayerList( BTOWER_APP_WORK * wk )
{
	GF_BGL_BMPWIN * win;
	GF_PRINTCOLOR	col;
	u16	list_pos;
	u16	i;

	if( wk->list_swap == 0 ){
		win = &wk->win[WINL_NAME01];
	}else{
		win = &wk->win[WINL_NAME11];
	}

	list_pos = wk->page * PLAYER_PUT_MAX;

	for( i=0; i<PLAYER_PUT_MAX; i++ ){
		GF_BGL_BmpWinDataFill( &win[i], 0 );

		if( list_pos < BTOWER_STOCK_WIFI_LEADER_MAX ){
			if( wk->leader[list_pos].sex == 0 ){
				col = FCOL_N_BLUE;
			}else{
				col = FCOL_N_RED;
			}
			StrPrintCore(
				&win[i], wk->leader[list_pos].name, 0, 0, FONT_SYSTEM, col, STRPRINT_MODE_LEFT );
		}

		GF_BGL_BmpWinOnVReq( &win[i] );

		list_pos++;
	}

	wk->list_swap ^= 1;
}

#define	LIST_PAGE_NUM_PX	( 8 )		// 現在のページ表示Ｘ座標
#define	LIST_PAGE_SRA_PX	( 16 )		// ページスラッシュ表示Ｘ座標
#define	LIST_PAGE_MAX_PX	( 24 )		// 最大ページ表示Ｘ座標

//--------------------------------------------------------------------------------------------
/**
 * ページ表示
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void PlayerListPageWrite( BTOWER_APP_WORK * wk )
{
	GF_BGL_BmpWinDataFill( &wk->win[WINL_PAGE], 0 );

	WORDSET_RegisterNumber(
		wk->msgDat.wset, 0, wk->page+1, 1,
		NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	ExStrPrint(
		wk, WINL_PAGE, msg_btwr_leader_page01,
		LIST_PAGE_NUM_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_RIGHT );

	StrPrint(
		wk, WINL_PAGE, msg_btwr_leader_page02,
		LIST_PAGE_SRA_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_CENTER );

	WORDSET_RegisterNumber(
		wk->msgDat.wset, 0, PLAYER_LIST_PAGE_MAX+1, 1,
		NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	ExStrPrint(
		wk, WINL_PAGE, msg_btwr_leader_page01,
		LIST_PAGE_MAX_PX, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );

	GF_BGL_BmpWinOnVReq( &wk->win[WINL_PAGE] );
}

/**
 *	@brief	歴代リーダー画面文字列初期描画
 */
static void BTowerApp_MsgWriteLeader(BTOWER_APP_WORK* wk)
{
	BTOWER_ROOMID roomid;
	u32	i;

	for( i=WINL_RET; i<=WINL_TITLE; i++ ){
		GF_BGL_BmpWinDataFill( &wk->win[i], 0 );
	}

	//「もどる」
	RetButtonStrPut( wk );

	//「ランク」
	TowerWifiData_GetLeaderDataRoomID( wk->wifiSave, &roomid );
	WORDSET_RegisterNumber(
		wk->msgDat.wset, 0, roomid.rank, 2, NUMBER_DISPTYPE_LEFT, NUMBER_CODETYPE_DEFAULT );
	ExStrPrint(
		wk, WINL_RANK, msg_btwr_leader_t01, 0, 0, FONT_SYSTEM, FCOL_N_WHITE, STRPRINT_MODE_LEFT );

	//「バトルルーム」
	WORDSET_RegisterNumber(
		wk->msgDat.wset, 1, roomid.no, 3, NUMBER_DISPTYPE_ZERO, NUMBER_CODETYPE_DEFAULT );
	ExStrPrint(
		wk, WINL_ROOM, msg_btwr_leader_t02, 0, 0, FONT_SYSTEM, FCOL_N_WHITE, STRPRINT_MODE_LEFT );

	// タイトル
	StrPrint(
		wk, WINL_TITLE, msg_btwr_leader_t03,
		0, 0, FONT_SYSTEM, FCOL_N_WHITE, STRPRINT_MODE_LEFT );

	for( i=WINL_RET; i<=WINL_TITLE; i++ ){
		GF_BGL_BmpWinOnVReq( &wk->win[i] );
	}

	// リーダーリスト
	BTowerApp_WritePlayerList( wk );

	// リーダー情報
	BTowerApp_WritePlayerInfo( wk, 0 );

	// リストページ
	PlayerListPageWrite( wk );
}

#define	INFOPUT_ADDR1_PY	( 0 )		// 住所１表示Ｙ座標
#define	INFOPUT_ADDR2_PY	( 16 )		// 住所２表示Ｙ座標
#define	INFOPUT_ADDR3_PY	( 32 )		// 住所３表示Ｙ座標
#define	INFOPUT_COMM1_PY	( 0 )		// コメント１表示Ｙ座標
#define	INFOPUT_COMM2_PY	( 16 )		// コメント２表示Ｙ座標

//--------------------------------------------------------------------------------------------
/**
 * プレイヤー情報表示
 *
 * @param	wk		成績画面ワーク
 * @param	pos		データ位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void BTowerApp_WritePlayerInfo( BTOWER_APP_WORK * wk, u32 pos )
{
	GF_BGL_BMPWIN * win;
	u16	winID;
	u16	i;

	if( wk->info_swap == 0 ){
		winID = WINL_INFO;
	}else{
		winID = WINL_INFO_S;
	}
	win = &wk->win[winID];

	for( i=0; i<3; i++ ){
		GF_BGL_BmpWinDataFill( &win[i], 0 );
	}

	if( pos < BTOWER_STOCK_WIFI_LEADER_MAX ){
		// リーダー情報
		WORDSET_RegisterWord(
			wk->msgDat.wset, 0, wk->leader[pos].name, wk->leader[pos].sex, TRUE, PM_LANG );
		if( wk->leader[pos].sex == 0 ){
			ExStrPrint(
				wk, winID, msg_btwr_leader_name01,
				0, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );
		}else{
			ExStrPrint(
				wk, winID, msg_btwr_leader_name02,
				0, 0, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );
		}

		// 住所
		StrPrint(
			wk, winID+1, msg_btwr_leader_area04,
			0, INFOPUT_ADDR1_PY, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );
		// 住んでいる国未登録時
		if( wk->leader[pos].country  == 0 ){
			StrPrint(
				wk, winID+1, msg_btwr_leader_area07,
				0, INFOPUT_ADDR2_PY, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );
		}else{
			WORDSET_RegisterCountryName( wk->msgDat.wset, 0, wk->leader[pos].country );
			ExStrPrint(
				wk, winID+1, msg_btwr_leader_area05,
				0, INFOPUT_ADDR2_PY, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );
		}
		// 住んでいる地域未登録時
		if( wk->leader[pos].area != 0 ){
			WORDSET_RegisterLocalPlaceName(
				wk->msgDat.wset, 0, wk->leader[pos].country, wk->leader[pos].area );
			ExStrPrint(
				wk, winID+1, msg_btwr_leader_area06,
				0, INFOPUT_ADDR3_PY, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );
		}

		// 挨拶
		StrPrint(
			wk, winID+2, msg_btwr_leader_comment,
			0, INFOPUT_COMM1_PY, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );
		{
			STRBUF * str = PMSDAT_ToString( &wk->leader[pos].msg, wk->heapID ); // 簡易会話を展開
			StrPrintCore(
				&win[2], str, 0, INFOPUT_COMM2_PY, FONT_SYSTEM, FCOL_N_BLACK, STRPRINT_MODE_LEFT );
			STRBUF_Delete( str );
		}
	}

	for( i=0; i<3; i++ ){
		GF_BGL_BmpWinOnVReq( &win[i] );
	}

	wk->info_swap ^= 1;
}

/**
 *	@brief	歴代リーダー画面 プレイヤーエリアコード描画
 */
static void BTowerApp_PlayerAreaMsgWrite(BTOWER_APP_WORK* wk)
{
/*
	LEADER_DATA* lp = &(wk->leader[wk->line*3+wk->side]);

	GF_BGL_BmpWinDataFill(&wk->win[WINL_TALK],APP_WINCLR_COL(FBMP_COL_NULL));
	if(lp->country  == 0 ){	//住んでいる場所未登録時
		GF_STR_PrintColor(&wk->win[WINL_TALK],FONT_SYSTEM,wk->msgDat.cbuf,
							0,4,MSG_ALLPUT,FCOLS_BLACK,NULL);
	}else if(lp->area == 0){
		//国コードのみ登録時
		WORDSET_RegisterCountryName(wk->msgDat.wset,0,lp->country);
		WORDSET_ExpandStr(wk->msgDat.wset,wk->msgDat.tmp,wk->msgDat.a2buf);

		GF_STR_PrintColor(&wk->win[WINL_TALK],FONT_SYSTEM,wk->msgDat.tmp,
							0,4,MSG_ALLPUT,FCOLS_BLACK,NULL);
	}else{
		//国コードとエリアコードを展開
		WORDSET_RegisterCountryName(wk->msgDat.wset,0,lp->country);
		WORDSET_RegisterLocalPlaceName(wk->msgDat.wset,1,lp->country,lp->area);
		WORDSET_ExpandStr(wk->msgDat.wset,wk->msgDat.tmp,wk->msgDat.a1buf);

		GF_STR_PrintColor(&wk->win[WINL_TALK],FONT_SYSTEM,wk->msgDat.tmp,
							0,4,MSG_ALLPUT,FCOLS_BLACK,NULL);
	}
	GF_BGL_BmpWinOn(&wk->win[WINL_TALK]);

	//選択カーソルのステート変更
	Act_CursorChg(wk,FALSE);
*/
}

/**
 *	@brief	歴代リーダー画面 プレイヤーメッセージ描画
 */
static void BTowerApp_PlayerMsgWrite(BTOWER_APP_WORK* wk)
{
/*
	STRBUF* str;
	LEADER_DATA* lp = &(wk->leader[wk->line*3+wk->side]);

	//簡易会話を展開
	str = PMSDAT_ToString(&lp->msg,wk->heapID);

	GF_BGL_BmpWinDataFill(&wk->win[WINL_TALK],APP_WINCLR_COL(FBMP_COL_NULL));
	GF_STR_PrintColor(&wk->win[WINL_TALK],FONT_SYSTEM,str,
						0,4,MSG_ALLPUT,FCOLS_BLACK,NULL);
	STRBUF_Delete(str);
*/
}

/**
 *	@brief	歴代リーダー画面　プレイヤーメッセージクリア
 */
static void BTowerApp_PlayerMsgClear(BTOWER_APP_WORK* wk)
{
/*
	GF_BGL_BmpWinDataFill(&wk->win[WINL_TALK],APP_WINCLR_COL(FBMP_COL_NULL));
	GF_BGL_BmpWinOff(&wk->win[WINL_TALK]);

	//選択カーソルのステート変更
	Act_CursorChg(wk,TRUE);
*/
}


static void BTowerApp_ActorInit(BTOWER_APP_WORK *wk)
{
//	initVramTransferManagerHeap(32,wk->heapID);

	//セルアクターシステム初期化
	wk->csp = CATS_AllocMemory(wk->heapID);
	wk->crp = CATS_ResourceCreate(wk->csp);

	{
		TCATS_OAM_INIT	coi = {
			0,128,		///< メイン	OAM管理領域・開始/終了
			0,32,		///< メイン	アフィン管理領域・開始/終了
			0,128,		///< サブ	OAM管理領域・開始/終了
			0,32,		///< サブ	アフィン管理領域・開始/終了
		};
		TCATS_CHAR_MANAGER_MAKE ccmm = {
			BTOWER_APP_ACTRES_MAX,	//ID制御数
			1024*64,	//メイン画面サイズ(byte単位)
			1024*16,	//サブ画面サイズ(byte単位)
			GX_OBJVRAMMODE_CHAR_1D_32K,	//メインOBJモード指定
			GX_OBJVRAMMODE_CHAR_1D_32K,	//サブOBJモード指定
		};

		CATS_SystemInit( wk->csp, &coi, &ccmm, 32 );
		CATS_ClactSetInit( wk->csp, wk->crp, ACT_MAX );
	}
	{
		TCATS_RESOURCE_NUM_LIST	crnl = {
			CHR_ID_MAX, PAL_ID_MAX, CEL_ID_MAX, ANM_ID_MAX, 0, 0
		};
		CATS_ResourceManagerInit( wk->csp, wk->crp, &crnl );
	}
	{
		CLACT_U_EASYRENDER_DATA * renddata = CATS_EasyRenderGet( wk->csp );
		CLACT_U_SetSubSurfaceMatrix( renddata, 0, BTS_SUB_ACTOR_DISTANCE );
	}

	{
		ARCHANDLE * ah = ArchiveDataHandleOpen( ARC_BTOWER_APP, wk->heapID );

		CATS_LoadResourceCharArcH(
			wk->csp, wk->crp, ah,
			NARC_btower_bf_leader_obj_lz_NCGR, 1, NNS_G2D_VRAM_TYPE_2DMAIN, CHR_ID_OBJ );

		CATS_LoadResourcePlttArcH(
			wk->csp, wk->crp, ah,
			NARC_btower_bf_leader_obj_NCLR, 0, PALSIZ_OBJ, NNS_G2D_VRAM_TYPE_2DMAIN, PAL_ID_OBJ );

		CATS_LoadResourceCellArcH(
			wk->csp, wk->crp, ah,
			NARC_btower_bf_leader_obj_lz_NCER, 1, CEL_ID_OBJ );

		CATS_LoadResourceCellAnmArcH(
			wk->csp, wk->crp, ah,
			NARC_btower_bf_leader_obj_lz_NANR, 1, ANM_ID_OBJ );

		ArchiveDataHandleClose( ah );
	}

	{
		u32	i;

		for( i=0; i<ACT_MAX; i++ ){
			wk->cap[i] = CATS_ObjectAdd_S( wk->csp, wk->crp, &ClaAddPrm[i] );
		}
		if( wk->mainMode == 0 ){
			CATS_ObjectEnableCap( wk->cap[ACT_L_ARROW], 0 );
			CATS_ObjectEnableCap( wk->cap[ACT_R_ARROW], 0 );
		}
	}

	GF_Disp_GX_VisibleControl( GX_PLANEMASK_OBJ, VISIBLE_ON );
//	GF_Disp_GXS_VisibleControl(GX_PLANEMASK_OBJ,VISIBLE_ON);
}

static void BTowerApp_ActorRelease(BTOWER_APP_WORK *wk)
{
/*
	CATS_ResourceDestructor(wk->csp,wk->crp);
	CATS_FreeMemory(wk->csp);
	DellVramTransferManager();
*/
	u32	i;

	for( i=0; i<ACT_MAX; i++ ){
		if( wk->cap[i] == NULL ){ continue; }
		CATS_ActorPointerDelete_S( wk->cap[i] );
		wk->cap[i] = NULL;
	}

	CATS_ResourceDestructor_S( wk->csp, wk->crp );
	CATS_FreeMemory( wk->csp );
}

static void BTowerApp_ActorMain(BTOWER_APP_WORK *wk)
{
/*
	if(wk->crp == NULL){
		return;
	}
	CATS_Draw(wk->crp);
*/
	u32	i;

	for( i=0; i<ACT_MAX; i++ ){
		CATS_ObjectUpdateCap( wk->cap[i] );
	}
	CATS_Draw( wk->crp );
}

static void BTowerApp_ActorTrans(void)
{
	CATS_RenderOamTrans();
}

//--------------------------------------------------------------------------------------------
/**
 * セルアクターアニメ変更
 *
 * @param	wk		成績画面ワーク
 * @param	id		OBJ ID
 * @param	anm		アニメ番号
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjAnmSet( BTOWER_APP_WORK * wk, u32 id, u32 anm )
{
	CATS_ObjectAnimeFrameSetCap( wk->cap[id], 0 );
	CATS_ObjectAnimeSeqSetCap( wk->cap[id], anm );
}

//--------------------------------------------------------------------------------------------
/**
 * セルアクターアニメチェック
 *
 * @param	wk		成績画面ワーク
 * @param	id		OBJ ID
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static BOOL ObjAnmCheck( BTOWER_APP_WORK * wk, u32 id )
{
	return CATS_ObjectAnimeActiveCheckCap( wk->cap[id] );
}

//--------------------------------------------------------------------------------------------
/**
 * セルアクター表示座標セット
 *
 * @param	wk		成績画面ワーク
 * @param	id		OBJ ID
 * @param	px		X座標
 * @param	py		Y座標
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ObjPosSet( BTOWER_APP_WORK * wk, u32 id, s16 px, s16 py )
{
	CATS_ObjectPosSetCap( wk->cap[id], px, py );
}




/**
 *	@brief	歴代リーダー画面　カーソルアクター状態チェンジ
 */
static void Act_CursorChg(BTOWER_APP_WORK* wk,BOOL mode)
{
/*
	BOOL flag;
	if(mode == FALSE){
		CLACT_PaletteNoChg(wk->pAct[ACT_CURSOR],ACT_CUR_PALF);
		flag = FALSE;
	}else{
		CLACT_PaletteNoChg(wk->pAct[ACT_CURSOR],ACT_CUR_PALT);
		flag = TRUE;
	}
	CLACT_SetAnmFlag(wk->pAct[ACT_CURSOR],flag);
	CLACT_SetAnmFlag(wk->pAct[ACT_UP],flag);
	CLACT_SetAnmFlag(wk->pAct[ACT_DOWN],flag);
*/
}

/**
 *	@brief	アクターカーソル位置セット
 */
static void Act_CursorPosSet(BTOWER_APP_WORK* wk,u8 line,u8 side,u8 viewLine)
{
/*
	u16 x,y;
	if(wk->upLine == LINE_RET-2){
		CLACT_SetDrawFlag(wk->pAct[ACT_RET], 1 );
		if(line == LINE_RET){
			CLACT_AnmFrameSet(wk->pAct[ACT_RET],1);
			CLACT_SetDrawFlag(wk->pAct[ACT_CURSOR], 0 );
		}else{
			CLACT_AnmFrameSet(wk->pAct[ACT_RET],0);
			CLACT_SetDrawFlag(wk->pAct[ACT_CURSOR], 1 );
		}
	}else{
		CLACT_SetDrawFlag(wk->pAct[ACT_CURSOR], 1 );
		CLACT_SetDrawFlag(wk->pAct[ACT_RET], 0 );
	}

	switch(wk->upLine){
	case 0:
		CLACT_SetDrawFlag(wk->pAct[ACT_UP], 0 );
		break;
	case LINE_SCR_MAX:
		CLACT_SetDrawFlag(wk->pAct[ACT_DOWN], 0 );
		break;
	default:
		CLACT_SetDrawFlag(wk->pAct[ACT_UP], 1 );
		CLACT_SetDrawFlag(wk->pAct[ACT_DOWN], 1 );
		break;
	}
	CATS_ObjectPosSet(wk->pAct[ACT_CURSOR],
			side*LIST_SIDE_WIDTH+ACT_CUR_PX,viewLine*24+ACT_CUR_PY);
*/
}




//--------------------------------------------------------------------------------------------
/**
 * ボタンアニメ処理
 *
 * @param	wk		成績画面ワーク
 *
 * @retval	"TRUE = アニメ中"
 * @retval	"FALSE = それ以外"
 */
//--------------------------------------------------------------------------------------------
static BOOL ButtonAnmMain( BTOWER_APP_WORK * wk )
{
	switch( wk->btn_seq ){
	case 0:
		if( wk->btn_mode == BTN_ANM_MODE_OBJ ){
			CATS_ObjectPaletteSetCap( wk->cap[wk->btn_id], wk->btn_pal1 );
		}else{
			GF_BGL_ScrPalChange(
				wk->bgl, wk->btn_id,
				wk->btn_px, wk->btn_py, wk->btn_sx, wk->btn_sy, wk->btn_pal1 );
			GF_BGL_LoadScreenV_Req( wk->bgl, wk->btn_id );
		}
		wk->btn_seq++;
		break;

	case 1:
		wk->btn_cnt++;
		if( wk->btn_cnt != 4 ){ break; }
		if( wk->btn_mode == BTN_ANM_MODE_OBJ ){
			CATS_ObjectPaletteSetCap( wk->cap[wk->btn_id], wk->btn_pal2 );
		}else{
			GF_BGL_ScrPalChange(
				wk->bgl, wk->btn_id,
				wk->btn_px, wk->btn_py, wk->btn_sx, wk->btn_sy, wk->btn_pal2 );
			GF_BGL_LoadScreenV_Req( wk->bgl, wk->btn_id );
		}
		wk->btn_cnt = 0;
		wk->btn_seq++;
		break;

	case 2:
		wk->btn_cnt++;
		if( wk->btn_cnt == 2 ){
			return FALSE;
		}
	}

	return TRUE;
}

//--------------------------------------------------------------------------------------------
/**
 * ボタンアニメ設定
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void ButtonAnmSet( BTOWER_APP_WORK * wk, u32 objID )
{
	wk->btn_mode = BTN_ANM_MODE_OBJ;
	wk->btn_id   = objID;
	wk->btn_pal1 = 1;
	wk->btn_pal2 = 0;

	wk->btn_seq = 0;
	wk->btn_cnt = 0;
}

//--------------------------------------------------------------------------------------------
/**
 * 「もどる」ボタンアニメ設定
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void RetButtonAnmSet( BTOWER_APP_WORK * wk )
{
	ButtonAnmSet( wk, ACT_RET );
}



// ステージ五十音入力ページ・タッチ座標テーブル
static const RECT_HIT_TBL LeaderHitTbl[] =
{
	{  56,  71,  21,  90 },
	{  56,  71,  93, 162 },
	{  56,  71, 165, 234 },

	{  80,  95,  21,  90 },
	{  80,  95,  93, 162 },
	{  80,  95, 165, 234 },

	{ 104, 119,  21,  90 },
	{ 104, 119,  93, 162 },
	{ 104, 119, 165, 234 },

	{ 128, 143,  21,  90 },
	{ 128, 143,  93, 162 },
	{ 128, 143, 165, 234 },

	{ 164, 187, 193, 254 },		// 12: もどる

	{ RECT_HIT_END, 0, 0, 0 }
};
// ステージ五十音入力ページ・キー動作テーブル
static const POINTER_WORK LeaderKeyTbl[] =
{
	{  56,  64, 0,0,	 0,  3,  2,  1 },
	{ 128,  64, 0,0,	 1,  4,  0,  2 },
	{ 200,  64, 0,0,	 2,  5,  1,  0 },

	{  56,  88, 0,0,	 0,  6,  5,  4 },
	{ 128,  88, 0,0,	 1,  7,  3,  5 },
	{ 200,  88, 0,0,	 2,  8,  4,  3 },

	{  56, 112, 0,0,	 3,  9,  8,  7 },
	{ 128, 112, 0,0,	 4, 10,  6,  8 },
	{ 200, 112, 0,0,	 5, 11,  7,  6 },

	{  56, 136, 0,0,	 6, 12, 11, 10 },
	{ 128, 136, 0,0,	 7, 12,  9, 11 },
	{ 200, 136, 0,0,	 8, 12, 10,  9 },

	{ OBJ_RET_BUTTON_PX, OBJ_RET_BUTTON_PY, 0, 0,	CURSORMOVE_RETBIT|11, 12, 12, 12 },		// 12: もどる
};
// ステージ五十音入力ページ・カーソル動作コールバック関数テーブル
static const CURSORMOVE_CALLBACK LeaderCallBack = {
	CursorMoveCallBack_Dummy,	// on,
	CursorMoveCallBack_Dummy,	// off
	LeaderCallBack_Move,		// move,
	LeaderCallBack_Touch,		// touch,
};

//--------------------------------------------------------------------------------------------
/**
 * ステージ五十音入力：カーソル移動ワーク作成
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void LeaderCursorMoveInit( BTOWER_APP_WORK * wk )
{
	wk->cmwk = CURSORMOVE_Create(
				LeaderHitTbl,
				LeaderKeyTbl,
				&LeaderCallBack,
				wk,
				TRUE,
				0,
				wk->heapID );

	LeaderSelCursorPut( wk, 0 );
}

//--------------------------------------------------------------------------------------------
/**
 * ステージ五十音入力：カーソル移動ワーク削除
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void LeaderCursorMoveExit( BTOWER_APP_WORK * wk )
{
	CURSORMOVE_Exit( wk->cmwk );
}

//--------------------------------------------------------------------------------------------
/**
 * ステージ五十音入力：指定位置にカーソル表示
 *
 * @param	wk		成績画面ワーク
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void LeaderSelCursorPut( BTOWER_APP_WORK * wk, int pos )
{
	const POINTER_WORK * pw;
	u8	x, y;

	pw = CURSORMOVE_PointerWorkGet( wk->cmwk, pos );
	PointerWkPosGet( pw, &x, &y );

	ObjPosSet( wk, ACT_CURSOR, x, y );
	if( pos == PLAYER_PUT_MAX ){
		ObjAnmSet( wk, ACT_CURSOR, OBJANM_RET_CURSOR );
	}else{
		ObjAnmSet( wk, ACT_CURSOR, OBJANM_NAME_CURSOR );
	}
}

//--------------------------------------------------------------------------------------------
/**
 * ステージ五十音入力：カーソル移動ダミーコールバック関数
 *
 * @param	wk			成績画面ワーク
 * @param	now_pos		現在位置
 * @param	old_pos		前回の位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void CursorMoveCallBack_Dummy( void * work, int now_pos, int old_pos )
{
}

//--------------------------------------------------------------------------------------------
/**
 * ステージ五十音入力：カーソル移動時のコールバック関数
 *
 * @param	wk			成績画面ワーク
 * @param	now_pos		現在位置
 * @param	old_pos		前回の位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void LeaderCallBack_Move( void * work, int now_pos, int old_pos )
{
	BTOWER_APP_WORK * wk;
	u32	pos;

	wk = work;

	wk->cm_page_change = 0;

	if( ( now_pos ==  2 && old_pos == 0 ) ||
		( now_pos ==  5 && old_pos == 3 ) ||
		( now_pos ==  8 && old_pos == 6 ) ||
		( now_pos == 11 && old_pos == 9 ) ){
		if( wk->page != 0 ){
			wk->page--;
		}else{
			wk->page = PLAYER_LIST_PAGE_MAX;
		}
		BTowerApp_WritePlayerList( wk );
		PlayerListPageWrite( wk );
		wk->cm_page_change = 1;
	}
	if( ( now_pos == 0 && old_pos ==  2 ) ||
		( now_pos == 3 && old_pos ==  5 ) ||
		( now_pos == 6 && old_pos ==  8 ) ||
		( now_pos == 9 && old_pos == 11 ) ){
		if( wk->page < PLAYER_LIST_PAGE_MAX ){
			wk->page++;
		}else{
			wk->page = 0;
		}
		BTowerApp_WritePlayerList( wk );
		PlayerListPageWrite( wk );
		wk->cm_page_change = 2;
	}

	if( now_pos == PLAYER_PUT_MAX ){
		pos = BTOWER_STOCK_WIFI_LEADER_MAX;
	}else{
		pos = wk->page * PLAYER_PUT_MAX + now_pos;
	}
	BTowerApp_WritePlayerInfo( wk, pos );

	LeaderSelCursorPut( work, now_pos );
}

//--------------------------------------------------------------------------------------------
/**
 * ステージ五十音入力：タッチ時のコールバック関数
 *
 * @param	wk			成績画面ワーク
 * @param	now_pos		現在位置
 * @param	old_pos		前回の位置
 *
 * @return	none
 */
//--------------------------------------------------------------------------------------------
static void LeaderCallBack_Touch( void * work, int now_pos, int old_pos )
{
	BTOWER_APP_WORK * wk;
	u32	pos;

	wk = work;

	if( now_pos == PLAYER_PUT_MAX ){
		pos = BTOWER_STOCK_WIFI_LEADER_MAX;
	}else{
		pos = wk->page * PLAYER_PUT_MAX + now_pos;
	}
	BTowerApp_WritePlayerInfo( wk, pos );

	LeaderSelCursorPut( work, now_pos );
}